

package functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.program;

import java.util.HashMap;

/**
 * A map object containing the arguments and the given values.
 * @author Jamie MacPherson
 */
public class ArgumentMap extends HashMap<Argument, Object> {


    /**
     * This constructor should be passed the arguments from the command line,
     * straight from the main method from the class <code>Main</code>.
     * The arguments will then be automatically set with the <code>setArguments(String args[])</code> method.
     * @param args
     */
    public ArgumentMap(String[] args) {
        setArguments(args);
    }

    /**
     * Takes an array of strings and populates the map with the key as an <code>Argument</code> object and a
     * Object of appropriate type, according to the requirement for the argument.
     * @param args the array of args passed in to the main method.
     */
    private void setArguments(String[] args) {
        for(int i=0;i<args.length;i++){
            Argument argument = Argument.getArgument(args[i].substring(1));
            if(argument != null){
                try{
                    this.put(argument, argument.getArgumentValue(args[i+1]));
                } catch(ArrayIndexOutOfBoundsException ex){
                    System.out.println("warning: no value was found for the argument "+argument.name()+" ("+argument.getTag()+")");

                }
            }
        }
    }



}
